package cc.admin.modules.graduate.service.impl;

import cc.admin.common.sys.vo.LoginUser;
import cc.admin.modules.graduate.entity.DTO.ExamPaperAnswerEnglishDto;
import cc.admin.modules.graduate.entity.ExamPaperAnswerEnglish;
import cc.admin.modules.graduate.mapper.ExamPaperAnswerEnglishMapper;
import cc.admin.modules.graduate.service.IExamPaperAnswerEnglishService;
import com.google.gson.Gson;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 试卷作答
 * @Author: cc-admin
 * @Date:   2025-02-23
 * @Version: V1.0.0
 */
@Service
public class ExamPaperAnswerEnglishServiceImpl extends ServiceImpl<ExamPaperAnswerEnglishMapper, ExamPaperAnswerEnglish> implements IExamPaperAnswerEnglishService {

    @Autowired
    private  ExamPaperAnswerEnglishMapper examPaperAnswerEnglishMapper;

    @Override
    public void saveExamAnswer(ExamPaperAnswerEnglishDto examPaperAnswer) {
        System.out.println(examPaperAnswer);
        ExamPaperAnswerEnglish examPaperAnswerEnglish = new ExamPaperAnswerEnglish();
        BeanUtils.copyProperties(examPaperAnswer,examPaperAnswerEnglish);

        Gson gson = new Gson();
        String blankAnswerString = gson.toJson(examPaperAnswer.getBlankAnswer());
        String yueduAnswerString = gson.toJson(examPaperAnswer.getYueduAnswer());
        String selectAnswerString = gson.toJson(examPaperAnswer.getSelectAnswer());
        String translateAnswerString = gson.toJson(examPaperAnswer.getTranslateAnswer());
        String writeAnswerString = gson.toJson(examPaperAnswer.getWriteAnswer());
        examPaperAnswerEnglish.setBlankAnswerString(blankAnswerString);
        examPaperAnswerEnglish.setYueduAnswerString(yueduAnswerString);
        examPaperAnswerEnglish.setSelectAnswerString(selectAnswerString);
        examPaperAnswerEnglish.setTranslateAnswerString(translateAnswerString);
        examPaperAnswerEnglish.setWriteAnswerString(writeAnswerString);

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String createBy = sysUser.getId();
        examPaperAnswerEnglish.setCreateBy(createBy);
        examPaperAnswerEnglish.setType("已审批");

        examPaperAnswerEnglishMapper.insert(examPaperAnswerEnglish);
        // 定义目标类型
//        java.lang.reflect.Type type = new TypeToken<List<List<String>>>() {}.getType();
//        List<List<String>> fromJson = gson.fromJson(blankAnswerString, type);
//        System.out.println(fromJson);

    }
}
